package com.zxy.service;

import com.zxy.util.LogBack;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;


public class TestService implements InitializingBean,ApplicationListener<ContextRefreshedEvent> {

    static final Logger logger = LoggerFactory.getLogger( TestService.class);

    @Autowired
    OperateService operateService;

    @Autowired
    ThreadHandle threadHandle;

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("------------------ afterPropertiesSet --------------------");
        //Thread t = new Thread(threadHandle);
        //threadHandle.start();

    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        System.out.println("------------------onApplicationEvent--------------------");
        //需要执行的逻辑代码，当spring容器初始化完成后就会执行该方法。
        if(event.getApplicationContext().getParent() == null){//root application context 没有parent，他就是老大.
            //需要执行的逻辑代码，当spring容器初始化完成后就会执行该方法。

        }
    }

    public TestService(){
        System.out.println(" -------------------- init TestService -------------- ");
        /*System.out.println(" -------------------- TestService -------------- ");
        System.out.println(" -------------------- operateService:" + operateService );
        logger.info( "--------------------- TestService ----------------------");
        threadHandle = new ThreadHandle();
        threadHandle.start();*/

        //threadHandle.start();
    }

}
